/**
 * file :	job.h
 * author :	bushaofeng
 * created :	2013-02-15 20:30
 * func : 
 */

#ifndef	__JOB_H_
#define	__JOB_H_

#include "logic.h"
#include "command.h"

class Job;
typedef void (Job::* _job_function)(int fd, BSONObj obj);

class Job{
    public:
        Job(LogicServer* logic):m_interface(logic->getInterface()),log(logic->getLog()){
            m_job_map[REQ_REGISTER] = &Job::job_register;
            m_job_map[REQ_LOGIN] = &Job::job_login;
            m_job_map[REQ_GETUSER] = &Job::job_getuser;
            m_job_map[REQ_GETFANS] = &Job::job_getfans;
            m_job_map[REQ_ADDFOLLOW] = &Job::job_addfollow;
            m_job_map[REQ_GETFOLLOWS] = &Job::job_getfollows;
            m_job_map[REQ_DELFOLLOW] = &Job::job_delfollow;
            m_job_map[REQ_ADDTOPIC] = &Job::job_addtopic;
            m_job_map[REQ_GETTOPIC] = &Job::job_gettopic;
            m_job_map[REQ_GETTOPICS] = &Job::job_gettopics;
            m_job_map[REQ_DELTOPIC] = &Job::job_deltopic;
            m_job_map[REQ_ADDPOST] = &Job::job_addpost;
            m_job_map[REQ_GETPOSTS] = &Job::job_getposts;
            m_job_map[REQ_DELPOST] = &Job::job_delpost;
            m_job_map[REQ_GETNEARUSERS] = &Job::job_getnearusers;
            m_job_map[REQ_GETNEARTOPICS] = &Job::job_getneartopics;
        }

        void job_register(int fd, BSONObj obj);
        void job_login(int fd, BSONObj obj);
        void job_getuser(int fd, BSONObj obj);
        void job_getfans(int fd, BSONObj obj);
        void job_addfollow(int fd, BSONObj obj);
        void job_getfollows(int fd, BSONObj obj);
        void job_delfollow(int fd, BSONObj obj);
        void job_addtopic(int fd, BSONObj obj);
        void job_gettopic(int fd, BSONObj obj);
        void job_gettopics(int fd, BSONObj obj);
        void job_deltopic(int fd, BSONObj obj);
        void job_addpost(int fd, BSONObj obj);
        void job_getposts(int fd, BSONObj obj);
        void job_delpost(int fd, BSONObj obj);
        void job_getnearusers(int fd, BSONObj obj);
        void job_getneartopics(int fd, BSONObj obj);

        _job_function   getJobMap(int type){
            assert(type>= 0 && type < REQ_NUM);
            return this->m_job_map[type];
        }
    private:
        _job_function   m_job_map[REQ_NUM];
        DBInterface&    m_interface;
        Log&            log;
};

#endif
